package netlink

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/vishvananda/netlink"
)

func main() {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)

	// 使用goroutine进行监听
	go func() {
		for {
			links, err := netlink.LinkList()
			if err != nil {
				log.Println("Error getting link list:", err)
				continue
			}

			// 打印每个链接的状态
			for _, link := range links {
				fmt.Printf("Link name: %s, state: %s\n", link.Attrs().Name, link.Attrs().OperState)
			}

			time.Sleep(time.Second * 5) // 5秒的暂停
		}

	}()

	<-make(chan struct{})
}
